package com.his.his_system.controller.DruginventoryController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.his.his_system.domain.DzmHisPrescriptionExtracharges;
import com.his.his_system.service.DzmHisPrescriptionExtrachargesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 处方附加费用
 */
@RestController
@RequestMapping("/api/")
public class DzmHisPrescriptionExtrachargesController {
    @Autowired
    private DzmHisPrescriptionExtrachargesService dzmHisPrescriptionExtrachargesService;
    /**
     * 显示附加费用页面
     */
    @GetMapping(value = "DzmHisPrescriptionExtrachargesxianshi")
    public List<DzmHisPrescriptionExtracharges>xs(){
        return dzmHisPrescriptionExtrachargesService.list();
    }
    /**
     * 附加费用修改
     */
    @PostMapping(value = "DzmHisPrescriptionExtrachargesxiugai")
    public Object xiugai1 (@RequestBody DzmHisPrescriptionExtracharges dzmHisPrescriptionExtracharges){
        UpdateWrapper<DzmHisPrescriptionExtracharges>updateWrapper=new UpdateWrapper<>();
        updateWrapper.eq("pre_id",dzmHisPrescriptionExtracharges.getPreId())
                .set("extracharges_name",dzmHisPrescriptionExtracharges.getExtrachargesName())
                .set("fee",dzmHisPrescriptionExtracharges.getFee())
                .set("type",dzmHisPrescriptionExtracharges.getType());
        return  dzmHisPrescriptionExtrachargesService.update(updateWrapper);
    }
    /**
     * 附加费用查询
     */
    @GetMapping(value = "DzmHisPrescriptionExtrachargeschaxun")
    public List<DzmHisPrescriptionExtracharges>chaxun1(String extrachargesName){
        QueryWrapper<DzmHisPrescriptionExtracharges>qu=new QueryWrapper<>();
        qu.like("extracharges_name",extrachargesName);
        return dzmHisPrescriptionExtrachargesService.list(qu);
    }
    /**
     * 附加费用添加
     */
    @PostMapping(value = "DzmHisPrescriptionExtrachargestianjia")
    public boolean tianjia1(@RequestBody  DzmHisPrescriptionExtracharges dzmHisPrescriptionExtracharges){
        System.out.println(dzmHisPrescriptionExtracharges.getType());
       return dzmHisPrescriptionExtrachargesService.save(dzmHisPrescriptionExtracharges);
    }
    /**
     * 附加费用删除
     */
    @DeleteMapping(value = "DzmHisPrescriptionExtrachargesshanchu")
    public boolean sc1(Integer preId){
        System.out.println(preId);
        Map<String,Object> map = new HashMap<>();
        map.put("pre_id",preId);
     return dzmHisPrescriptionExtrachargesService.removeByMap(map);
    }

    
}
